package com.ichinait.bridge.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ichinait.bridge.db.entity.User;
import com.ichinait.bridge.dto.UserDTO;
import com.ichinait.bridge.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("user")
public class UserController {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Autowired
    UserService userService;

    @RequestMapping("list")
    public String toListPage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        return "bridge/user/user_list";
    }


    @RequestMapping("page")
    @ResponseBody
    public Map<String,Object> page(UserDTO userDTO){
        Map<String,Object> result = new HashMap<>();
        Page<User> page = userService.page(userDTO);
        result.put("code",0);
        result.put("msg", "");
        result.put("data",page.getRecords());
        result.put("count", page.getTotal());
        return result;
    }
}
